import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

# 实例化Options来创建启动参数对象
options = webdriver.ChromeOptions()
# 启动无痕模式运行
options.add_argument('--incognito')
# 设置窗口最大化运行
options.add_argument('--start-maximized')
# 取消Chrome正受到自动测试软件的控制的提示
options.add_experimental_option('useAutomationExtension', False)
options.add_experimental_option("excludeSwitches", ['enable-automation'])
# 启动浏览器
driver = webdriver.Chrome(options=options)
# 设置隐式等待
driver.implicitly_wait(3)
# 防止被反爬
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
    "source": """
    Object.defineProperty(navigator, 'webdriver', {
      get: () => false
    })
  """
})

# 身份证号码生成
driver.get('https://xbeginagain.github.io/generator/')
time.sleep(3)

# 所在地-省份
province = driver.find_element(By.ID, 'province')
Select(province).select_by_value("410000")
time.sleep(3)

# 所在地-市区
city = driver.find_element(By.ID, 'city')
Select(city).select_by_value("411500")
time.sleep(3)

# 所在地-区县
county = driver.find_element(By.ID, 'county')
Select(county).select_by_value("411502")
time.sleep(3)

# 退出浏览器
driver.quit()
